<template>
    <div>
        <div class="e-h-400" ref="chart" :id="id"></div>
        <!-- <div>{{ data }}}</div> -->
    </div>
</template>

<script>
import * as echarts from 'echarts';

export default {
    props: {
        id: '',
        data: []
    },
    watch: {
        data(val) {
            this.init()
        }
    },
    mounted() {
        console.log('mountedID', this.id)
        console.log('data', this.data)

        this.init()
    },
    methods: {
        init(){
            
            var chartDom = document.getElementById(this.id);
            var myChart = echarts.init(chartDom);
            var option;
            
            //获取数据
            option = {
                title: {
                    // text: 'World Population'
                },
                tooltip: {
                    trigger: 'item'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [
                    {
                        name: '回收订单',
                        type: 'pie',
                        radius: '50%',
                        // data: [
                        //     { value: 1048, name: '线下订单' },
                        //     { value: 735, name: '线上订单' },
                        // ],
                        data: this.data,
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };

            option && myChart.setOption(option);
        }
    }
}
</script>

<style lang="scss" scoped></style>